package com.oig.sys.log.event;


import com.oig.sys.log.dto.SysLogDto;
import com.oig.sys.log.feign.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;


@Slf4j
public class SysLogEventListener {

    private final SysLogService sysLogService;

    public SysLogEventListener(SysLogService sysLogService){
        this.sysLogService = sysLogService;
    }


    @Async
    @Order
    @EventListener(SysLogEvent.class)
    public void saveSysLog(SysLogEvent event) {
        log.debug("触发记录日志事件");
        SysLogDto sysLog = (SysLogDto) event.getSource();
        sysLogService.addSysLog(sysLog, event.getToken());
    }

}
